package com.ruoyi.product.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.product.domain.TbCourse;
import com.ruoyi.product.service.ITbCourseService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 课程Controller
 * 
 * @author Sun
 * @date 2023-01-30
 */
@RestController
@RequestMapping("/course")
public class TbCourseController extends BaseController
{
    @Autowired
    private ITbCourseService tbCourseService;

    /**
     * 查询课程列表
     */
    @RequiresPermissions("product:course:list")
    @GetMapping("/list1")
    public TableDataInfo list(TbCourse tbCourse)
    {
        startPage();
        List<TbCourse> list = tbCourseService.selectTbCourseList(tbCourse);
        return getDataTable(list);
    }

    /**
     * 导出课程列表
     */
    @RequiresPermissions("product:course:export")
    @Log(title = "课程", businessType = BusinessType.EXPORT)
    @PostMapping("/export1")
    public void export(HttpServletResponse response, TbCourse tbCourse)
    {
        List<TbCourse> list = tbCourseService.selectTbCourseList(tbCourse);
        ExcelUtil<TbCourse> util = new ExcelUtil<TbCourse>(TbCourse.class);
        util.exportExcel(response, list, "课程数据");
    }

    /**
     * 获取课程详细信息
     */
    @RequiresPermissions("product:course:query")
    @GetMapping(value = "/getInfo1/{courseId}")
    public AjaxResult getInfo(@PathVariable("courseId") Integer courseId)
    {
        return success(tbCourseService.selectTbCourseByCourseId(courseId));
    }

    /**
     * 新增课程
     */
    @RequiresPermissions("product:course:add")
    @Log(title = "课程", businessType = BusinessType.INSERT)
    @PostMapping("/add1")
    public AjaxResult add(@RequestBody TbCourse tbCourse)
    {
        return toAjax(tbCourseService.insertTbCourse(tbCourse));
    }

    /**
     * 修改课程
     */
    @RequiresPermissions("product:course:edit")
    @Log(title = "课程", businessType = BusinessType.UPDATE)
    @PutMapping("/edit1")
    public AjaxResult edit(@RequestBody TbCourse tbCourse)
    {
        return toAjax(tbCourseService.updateTbCourse(tbCourse));
    }

    /**
     * 删除课程
     */
    @RequiresPermissions("product:course:remove")
    @Log(title = "课程", businessType = BusinessType.DELETE)
	@DeleteMapping("/remove1/{courseIds}")
    public AjaxResult remove(@PathVariable Integer[] courseIds)
    {
        return toAjax(tbCourseService.deleteTbCourseByCourseIds(courseIds));
    }
}
